var ns;
var app = new Vue({
    el: '#app',
    data: {
        form: {
            keywords: '',
            pageindex: 0,
            pagesize: 10,
        },
        scroll_top: 0,
        can_scroll: true,
        is_searching: false,
        list: [],
        PlanType: 3,
        ProjectID: 0
    },
    methods: {
        get_data: function() {
            var that = this;
            that.can_scroll = false;
            var options = {};
            options.action = "getequipmentdevicelist";
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.keywords = that.form.keywords;
            options.PlanType = that.PlanType;
            options.ProjectID = that.ProjectID;
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.list = data.list;
                    } else {
                        that.list = that.list.concat(data.list);
                    }
                    app.current_item_length = that.list.length
                } else if (err) {
                    // that.list = [];
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        do_search: function() {
            var that = this;
            that.form.pageindex = 0;
            that.get_data();
        },
        do_choose: function(item) {
            var that = this;
            var selectitem = item;
            api.sendEvent({
                name: 'do_choose_patrol_done',
                extra: {
                    id: selectitem.ID,
                    name: selectitem.PatrolName,
                    projectname: selectitem.ProjectName,
                    IsAllowUpload: selectitem.IsAllowUpload
                }
            });
            api.closeWin();
            return;
            for (var i = 0; i < that.list.length; i++) {
                if (that.list[i].ID == item.ID) {
                    continue;
                }
                that.list[i].isselect = false;
            }
            item.isselect = !item.isselect;
        },
        do_save: function() {
            var that = this;
            var selectitem = null;
            for (var i = 0; i < that.list.length; i++) {
                if (that.list[i].isselect) {
                    selectitem = that.list[i];
                }
            }
            if (selectitem == null) {
                api.toast({
                    msg: '请选择一个巡更点',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.sendEvent({
                name: 'do_choose_patrol_done',
                extra: {
                    id: selectitem.ID,
                    name: selectitem.PatrolName,
                    projectname: selectitem.ProjectName,
                    IsAllowUpload: selectitem.IsAllowUpload
                }
            });
            api.closeWin();
        },
        clear_searchVal: function() {
            var that = this;
            document.getElementById("search-input").value = '';
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    app.ProjectID = api.pageParam.projectid || 0;
    setTimeout(function() {
        app.get_data();
    }, 500)
    ns.init_search();
    ns.init_pull();
}
